package com.course.mapper;
/*
@author By 林中小鸟
@package  com.self.introduction.bean
@create 2021 - 09 - 2021\9\23 0023
@QQ: 357182695
@Em: themooncss@gmail.com
*/

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.course.entity.Permission;
import com.course.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public interface UserMapper extends BaseMapper<User> {
    @Select("SELECT DISTINCT r.`name` FROM user_role ur LEFT JOIN role r on  ur.role_id = r.id WHERE ur.user_id=#{user_id} ")
    List<Map<String, Object>> getUserRols(Long user_id);
    @Select("SELECT DISTINCT p.`id` as Skey,p.*,p.`meta` as metaJson FROM user_role ur LEFT JOIN role r on  ur.role_id = r.id LEFT JOIN role_permission rp on  r.id = rp.role_id LEFT JOIN permission p on  p.id = rp.permission_id WHERE ur.user_id=#{userID} ")
    List<Permission> getUserPermissions(Long userID);
    @Delete("DELETE FROM user_role WHERE user_id in (0, #{values});")
    Boolean unLinkRole(Long values);
    @Insert("INSERT INTO user_role (`user_id`,`role_id`) VALUES (#{user_id},#{role_id})")
    Boolean linkRole(Long user_id,Long role_id);
}
